local skel = fk.CreateSkill {
  name = "emo__mingshi",
  tags = {Skill.Compulsory},
}

skel:addEffect(fk.RoundStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = room:getOtherPlayers(player, false)
    if #targets == 0 then return end
    local to = #targets == 1 and targets[1] or room:askToChoosePlayers(player, {
      targets = targets, max_num = 1, min_num = 1, skill_name = skel.name, cancelable = false,
      prompt = "#emo__mingshi-choose",
    })[1]
    local old = room:getPlayerById(player:getMark("@[chara]emo__mingshi"))
    room:setPlayerMark(player, "@[chara]emo__mingshi", to.id)
    if old and old ~= to and not old:isNude() then
      local id = room:askToChooseCard(player, {target = old, flag = "he", skill_name = skel.name})
      room:obtainCard(player, id, false, fk.ReasonPrey, player, skel.name)
      if not player:isNude() and not to.dead then
        local give = room:askToCards(player, {
          max_num = 1, min_num = 1, skill_name = skel.name, cancelable = false, include_equip = true,
          prompt = "#emo__mingshi-give:"..to.id,
        })
        room:obtainCard(to, give, false, fk.ReasonGive, player, skel.name)
      end
    end
  end,
})

skel:addEffect(fk.Damage, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target and target.id == player:getMark("@[chara]emo__mingshi")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local lord = room:getPlayerById(player:getMark("@[chara]emo__mingshi"))
    player:drawCards(2, skel.name)
    if not player:isKongcheng() and not lord.dead then
      local cards = room:askToCards(player, {
        min_num = 1, max_num = player:getHandcardNum(), skill_name = skel.name, cancelable = false, include_equip = false,
        prompt = "#emo__mingshi-give:"..lord.id,
      })
      room:obtainCard(lord, cards, false, fk.ReasonGive, player, skel.name)
    end
  end,
})

Fk:loadTranslationTable{
  ["emo__mingshi"] = "明势",
  [":emo__mingshi"] = "锁定技，每轮开始时，你标记一名其他角色为你的“君”，若你此前已有“君”，你获得其一张牌，然后交给新的“君”一张牌。每当你的“君”造成伤害后，你摸两张牌，然后交给其至少一张手牌。",
  ["#emo__mingshi-choose"] = "明势：你标记一名其他角色为你的“君”",
  ["@[chara]emo__mingshi"] = "君",
  ["#emo__mingshi-give"] = "明势：交给 %src 一张牌",
  ["#emo__mingshi-givemore"] = "明势：交给 %src 至少一张手牌",
}


return skel
